package com.hx01.modules.sys.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hx01.common.annotation.SysLog;
import com.hx01.modules.sys.entity.SysDictEntity;
import com.hx01.modules.sys.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * (SysDict)表控制层
 *
 * @author makejava
 * @since 2020-12-20 21:52:48
 */
@RestController
@RequestMapping("sysDict")
@Api(tags = "系统字典表")
public class SysDictController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private SysDictService sysDictService;

    /**
     * 分页查询所有数据
     *
     * @param page    分页对象
     * @param sysDict 查询实体
     * @return 所有数据
     */
    @GetMapping("/list")
    @ApiOperation("分页查询所有数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页大小", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "desc", value = "倒序排序字段与asc二选一，排序字段需要驼峰转换成下划线", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "asc", value = "正序排序字段与desc二选一, 排序字段需要驼峰转换成下划线", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "id", value = "主键", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "code", value = "代码值", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "name", value = "代码中文名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "分组类型", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupName", value = "分组名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "状态  0：禁用   1：正常", required = false, dataTypeClass = Object.class),
            @ApiImplicitParam(name = "createUserId", value = "创建者ID", required = false, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", required = false, dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateUserId", value = "更新者ID", required = false, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", required = false, dataTypeClass = Date.class),
    })
    public R selectAll(Page<SysDictEntity> page, SysDictEntity sysDict) {
        return success(this.sysDictService.page(page, new QueryWrapper<>(sysDict)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "数据主键id", required = true, dataTypeClass = String.class)
    })
    public R selectOne(@PathVariable Serializable id) {
        return success(this.sysDictService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysDict 实体对象
     * @return 新增结果
     */
    @SysLog("新增数据")
    @PostMapping("/save")
    @ApiOperation("新增数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "code", value = "代码值", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "name", value = "代码中文名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "分组类型", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupName", value = "分组名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "状态  0：禁用   1：正常", required = false, dataTypeClass = Object.class),
            @ApiImplicitParam(name = "createUserId", value = "创建者ID", required = false, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", required = false, dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateUserId", value = "更新者ID", required = false, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", required = false, dataTypeClass = Date.class),
    })
    public R insert(@RequestBody SysDictEntity sysDict) {
        return success(this.sysDictService.save(sysDict));
    }

    /**
     * 修改数据
     *
     * @param sysDict 实体对象
     * @return 修改结果
     */
    @SysLog("修改数据")
    @PostMapping("/update")
    @ApiOperation("修改数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = false, dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "code", value = "代码值", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "name", value = "代码中文名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupType", value = "分组类型", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "groupName", value = "分组名称", required = false, dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "状态  0：禁用   1：正常", required = false, dataTypeClass = Object.class),
            @ApiImplicitParam(name = "createUserId", value = "创建者ID", required = false, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", required = false, dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateUserId", value = "更新者ID", required = false, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", required = false, dataTypeClass = Date.class),
    })
    public R update(@RequestBody SysDictEntity sysDict) {
        return success(this.sysDictService.updateById(sysDict));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @SysLog("删除数据")
    @PostMapping("/delete")
    @ApiOperation("删除数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "idList", value = "主键数据集合", required = true, dataTypeClass = List.class)
    })
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.sysDictService.removeByIds(idList));
    }
}